package com.dgut.epidemic.service;

import com.dgut.epidemic.mapper.UserMangerMapper;
import com.dgut.epidemic.pojo.Daily_data;
import com.dgut.epidemic.pojo.WeChatUser;
import com.dgut.epidemic.utils.SubList;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.*;

/**
 * Author: wuhaoduan
 * Date: 2021/6/12 18:37
 */
@Service
public class UserMangerServiceImpl implements UserMangerService{

    @Autowired
    private UserMangerMapper userMangerMapper;

    @Override
    public List<WeChatUser> getAllWeChatUser() {
        List<WeChatUser> weChatUsers = userMangerMapper.getAllWeChatUser();
        for(int i=0;i<weChatUsers.size();i++){
            weChatUsers.get(i).setIsSubmit(userMangerMapper.judgeUserIsSubmit(weChatUsers.get(i).getId()));
        }
        return weChatUsers;
    }

    @Override
    public List<Integer> getAllWeChatUserSubmit(List<WeChatUser> weChatUsers) {
        List<Integer> submits = new ArrayList<>();
        for(int i=0;i<weChatUsers.size();i++){
            submits.add(userMangerMapper.judgeUserIsSubmit(weChatUsers.get(i).getId()));
        }
        return submits;
    }

    @Override
    public List<WeChatUser> getWeChatUserAfter(List<WeChatUser> weChatUsers, int pageNum, int pageSize) throws Exception {
        SubList subList = new SubList();
        List<WeChatUser> weChatUserList = subList.subList(weChatUsers,pageNum,pageSize);
        return weChatUserList;
    }

    @Override
    public void lockWeChatUser(String id) {
        userMangerMapper.lockWeChatUser(id);
    }

    @Override
    public void unlockWeChatUser(String id) {
        userMangerMapper.unlockWeChatUser(id);
    }

    @Override
    public List<Daily_data> getALLDailyDataById(String id){
        List<Daily_data> daily_data = userMangerMapper.getAllDailyDataBySno(id);
        return daily_data;
    }

    @Override
    public List<Daily_data> getDailyDataAfter(List<Daily_data> daily_data, int pageNum, int pageSize) throws Exception {
        SubList subList = new SubList();
        List<Daily_data> daily_data1 = subList.subList(daily_data,pageNum,pageSize);
        return daily_data1;
    }

    @Override
    public List<WeChatUser> getWeChatUserOrderStaus() {
        List<WeChatUser> weChatUsers = userMangerMapper.getWeChatUserOrderStaus();
        for(int i=0;i<weChatUsers.size();i++){
            weChatUsers.get(i).setIsSubmit(userMangerMapper.judgeUserIsSubmit(weChatUsers.get(i).getId()));
        }
        return weChatUsers;
    }

    @Override
    public List<WeChatUser> getWeChatUserOrderType() {
        List<WeChatUser> weChatUsers = userMangerMapper.getWeChatUserOrderType();
        for(int i=0;i<weChatUsers.size();i++){
            weChatUsers.get(i).setIsSubmit(userMangerMapper.judgeUserIsSubmit(weChatUsers.get(i).getId()));
        }
        return weChatUsers;
    }

    @Override
    public List<WeChatUser> getWeChatUserOrderID() {
        List<WeChatUser> weChatUsers = userMangerMapper.getWeChatUserOrderID();
        for(int i=0;i<weChatUsers.size();i++){
            weChatUsers.get(i).setIsSubmit(userMangerMapper.judgeUserIsSubmit(weChatUsers.get(i).getId()));
        }
        return weChatUsers;
    }

    @Override
    public List<WeChatUser> getWeChatUserOrderToday() {
        List<WeChatUser> weChatUsers = userMangerMapper.getAllWeChatUser();
        for(int i=0;i<weChatUsers.size();i++){
            weChatUsers.get(i).setIsSubmit(userMangerMapper.judgeUserIsSubmit(weChatUsers.get(i).getId()));
        }
        weChatUsers.sort(Comparator.comparing(WeChatUser::getIsSubmit));
        return weChatUsers;
    }
}
